//
// Created by ftd on 2021/8/18.
//

#ifndef DEMO_DEMO_H
#define DEMO_DEMO_H
#include <thread>
#include <vector>
#include <condition_variable>
#include <mutex>
#include "utils/ring_buffer.h"

class Demo {
public:
    ~Demo();
    Demo(const Demo&) = delete;
    Demo& operator= (const Demo&) = delete;
    static Demo& Instance();
    bool StartUp(int argc, char *argv[]);
    void Run();
    void Exit();

    //存放一个接收到的网络消息到ring buffer
    void PutMsg(uint8_t* msg_buffer, int msg_size);

    inline bool IsExit() {
        return is_exit_;
    }

    inline bool IsStressTest() {
        return is_stress_test_;
    }
private:
    Demo();
    bool StartHandleThread();
    // 网络消息事件处理转发
    void HandleEvent();

    // 程序退出标识
    bool is_exit_;
    bool is_stress_test_;
    // 处理网络消息线程
    std::vector<std::thread> handle_threads_;
    // 网络消息接收存储
    RingBuffer ring_buffer_;
    std::mutex mutex_;
    std::condition_variable cond_;
};


#endif //DEMO_DEMO_H
